<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<!-- 循环渲染轮播图的 item 项 -->
			<swiper-item v-for="item in swiperList" :key="item.goods_id" @click="toGoodsDetail(item.goods_id)">

				<view class="swiper-item">
					<!-- 动态绑定图片的 src 属性 -->
					<image :src="item.image_src"></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- nav -->
		<view class="nav-list">
			<view class="nav-item" v-for="item in navList" :key="item.name">
				<navigator url="/pages/cate/cate" open-type="switchTab" v-if="item.name === '分类'">
					<image class="nav-img" :src="item.image_src"></image>
				</navigator>
				<image class="nav-img" :src="item.image_src" v-else></image>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<!-- 楼层 item 项 -->
			<view class="floor-item" v-for="item in floorList" :key="item.floor_title.name">
				<!-- 楼层标题 -->
				<image class="floor-title" :src="item.floor_title.image_src"></image>
				<view class="floor-img-box">
					<!-- 左侧大图片的盒子 -->
					<view class="left-img-box">
						<image @click="toGoodList(item.product_list[0])" mode="widthFix"
							:style="{width:item.product_list[0].image_width + 'rpx'}"
							:src="item.product_list[0].image_src"></image>
					</view>
					<!-- 右侧 4 个小图片的盒子 -->
					<view class="right-img-box">
						<view class="right-img-item" v-for="(item2,i) in item.product_list" :key="i">
							<image @click="toGoodList(item2)" mode="widthFix" v-if="i!==0" :src="item2.image_src"
								:style="{width:item2.image_width + 'rpx'}">
							</image>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		async onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()

		},
		methods: {
			async getFloorList() {
				const {
					data
				} = await uni.$http.get("/home/floordata")
				if (data.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.floorList = data.message
			},
			async getNavList() {
				const {
					data
				} = await uni.$http.get("/home/catitems")
				if (data.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.navList = data.message
			},
			toGoodsDetail(goods_id) {
				console.log(1);
				uni.navigateTo({
					url: "/subpkg/goods_detail/goods_detail?goods_id=" + goods_id,
				})
			},
			async getSwiperList() {
				const {
					data: res
				} = await uni.$http.get("/home/swiperdata")
				if (res.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.swiperList = res.message
			},
			toGoodList(item) {
				uni.navigateTo({
					url: "/subpkg/goods_detail/goods_detail?" + item.navigator_url.split("?").at(-1)
				})
			}
		},

	}
</script>

<style lang="scss">
	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 30rpx 0;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-title {
		height: 60rpx;
		width: 100%;
		display: flex;
	}

	.right-img-box {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}

	.floor-img-box {
		display: flex;
		padding-left: 10rpx;
	}
</style>